//
//  LPCostomJudgeIsOrFalseView.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/1.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPCostomJudgeIsOrFalseView.h"
#import "LPChooseTitleShowTitleView.h"
#import "YBPopupMenu.h"
@interface LPCostomJudgeIsOrFalseView ()<LPChooseTitleShowTitleViewDelegate,YBPopupMenuDelegate>
/**  label  */
@property (strong, nonatomic) UILabel  *lpLabel;
/**  安妮  */
@property (strong, nonatomic) UIImageView  *sureButton;
/**  是否选中  */
@property (assign, nonatomic) BOOL   isChoose;
/**  显示的类型  */
@property (strong, nonatomic) LPChooseTitleShowTitleView  *typeLabel;


@end
@implementation LPCostomJudgeIsOrFalseView

- (instancetype)initWithFrame:(CGRect)frame judge:(NSString *)judge
{
    self = [super initWithFrame:frame];
    if (self) {
        self.isChoose = NO;
        self.lpLabel.text = judge;
//        CGFloat width = [CalculateLabelHeight CalculateLabelWidthWithString:judge font:15 * [UIScreen zj_textFontScale] height:40 * [UIScreen zj_screenHScale]].width;
        [self addSubview:self.lpLabel];
        self.lpLabel.sd_layout
        .leftSpaceToView(self, 10 * [UIScreen zj_screenWScale])
        .topEqualToView(self)
        .widthIs(150 * [UIScreen zj_screenWScale])
        .heightIs(40 * [UIScreen zj_screenHScale]);
        
        
        [self addSubview:self.sureButton];
        self.sureButton.sd_layout
        .leftSpaceToView(self.lpLabel, 30 * [UIScreen zj_screenWScale])
        .topSpaceToView(self, 5 * [UIScreen zj_screenHScale])
        .heightIs(30 * [UIScreen zj_screenHScale])
        .widthIs(30 * [UIScreen zj_screenHScale]);
        
        [self addSubview:self.typeLabel];
        self.typeLabel.hidden = YES;
        self.typeLabel.sd_layout
        .topSpaceToView(self.lpLabel, 10 * [UIScreen zj_screenHScale])
        .leftEqualToView(self)
        .heightIs(18 * [UIScreen zj_screenHScale])
        .rightSpaceToView(self, 0 * [UIScreen zj_screenWScale]);
        
    }
    return self;
}

- (void)tapImageView{
    if (self.isChoose) {
        self.isChoose = NO;
        self.sureButton.image = [UIImage imageNamed:@"option_default"];
    }else{
        self.isChoose = YES;
        self.sureButton.image = [UIImage imageNamed:@"option_normal"];
    }
    if (self.delegate) {
        [self.delegate LPCostomJudgeIsOrFalseWithView:self Status:self.isChoose];
    }
}

- (void)setShowStringArray:(NSArray *)showStringArray{
    _showStringArray = showStringArray;
    if (showStringArray.count != 0) {
        self.typeLabel.hidden = NO;
        self.typeLabel.showString = showStringArray[0];
        
    }else{
        self.typeLabel.hidden = YES;
    }
}

#pragma mark - YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu{
    self.typeLabel.showString = self.showStringArray[index];
    if (self.delegate) {
        [self.delegate LPCostomJudgeIsOrFalseWithView:self clickIndex:index];
    }
}

#pragma mark - LPChooseTitleShowTitleViewDelegate
- (void)LPChooseTitleShowTitleView_click{
    [YBPopupMenu showRelyOnView:self.typeLabel titles:self.showStringArray icons:@[] menuWidth:[UIScreen zj_screenWith] - 80 * [UIScreen zj_screenWScale] showCount:0  delegate:self];
}

- (UILabel *)lpLabel{
    if (!_lpLabel) {
        _lpLabel = ({
            UILabel *label = [UILabel new];
            label.textAlignment = NSTextAlignmentLeft;
            label.textColor = [UIColor textBlackColor];
            label.backgroundColor = [UIColor clearColor];
            label.font = LYPFONT(15);
            label;
        });
    }
    return _lpLabel;
}

- (UIImageView *)sureButton{
    if (!_sureButton) {
        _sureButton = ({
            UIImageView *button = [UIImageView new];
            button.userInteractionEnabled = YES;
            button.contentMode = UIViewContentModeCenter;
            button.image = [UIImage imageNamed:@"option_default"];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
            [button addGestureRecognizer:tap];
            button;
            
        });
    }
    return _sureButton;
}

- (LPChooseTitleShowTitleView *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = [LPChooseTitleShowTitleView new];
        _typeLabel.delegate = self;
    }
    return _typeLabel;
}


@end
